#include "cv.h"
#include "highgui.h"
#include <string>
using namespace std;

/**
 * erode
 * @param: IplImage* image : input image
 * @return: IplImage* image : output image
 */
IplImage* erode(IplImage* image){
	//create the output image
	IplImage* imageOut = cvCreateImage(cvGetSize(image), image->depth, image->nChannels);
	//do erode
	cvErode(image, imageOut, NULL, 1);
	return imageOut;
}

/**
 * dilate
 * @param: IplImage* image : input image
 * @return: IplImage* image : output image
 */
IplImage* dilate(IplImage* image){
	//create the output image
	IplImage* imageOut = cvCreateImage(cvGetSize(image), image->depth, image->nChannels);
	//do dilate
	cvDilate(image, imageOut, NULL, 1);
	return imageOut;
}

/**
 * main
 * @param: 
 * @return: 
 */
void main(){
	string filePath = "test.jpg";
	//define window
	string windowNameIn = "in";
	string windowNameOutErode = "erode";
	string windowNameOutDilate = "dilate";
	cvNamedWindow(windowNameIn.data());
	cvNamedWindow(windowNameOutErode.data());
	cvNamedWindow(windowNameOutDilate.data());
	//load image
	IplImage* image = cvLoadImage(filePath.data());
	//show the input image
	cvShowImage(windowNameIn.data(), image);

	//handle image
	IplImage* imageOutErode = NULL;
	IplImage* imageOutDilate = NULL;
	imageOutErode = erode(image);
	imageOutDilate = dilate(image);

	//show output image
	cvShowImage(windowNameOutErode.data(), imageOutErode);
	cvShowImage(windowNameOutDilate.data(), imageOutDilate);
	//waitKey
	cvWaitKey(0);
	//release;
	cvReleaseImage(&image);
	cvReleaseImage(&imageOutErode);
	cvReleaseImage(&imageOutDilate);
	cvDestroyWindow(windowNameIn.data());
	cvDestroyWindow(windowNameOutErode.data());
	cvDestroyWindow(windowNameOutDilate.data());
}